package day05;
import java.util.Scanner;
import java.math.BigDecimal;
public class Addition {
    public static void main(String[] args) {
        // 随机生成20个100以内+-*/
        Scanner scan = new Scanner(System.in);
        int score = 0;//初始总分
        for (int i = 1; i <= 20; i++) {
            int a = (int) (Math.random() * 100 + 1);//出题
            int b = (int) (Math.random() * 100 + 1);
            int a2 = (int) (Math.random() * 10 + 1);//判断+-或*/
            int a3 = (int) (Math.random() * 10 + 1);//判断+-*/
            if (a2 > 5) {
                if (a3 > 5) {
                    System.out.println(i + "." + " " + a + "+" + b + "=?");
                    System.out.println("算吧");
                    double sum = scan.nextDouble();
                    if (sum == a + b) {
                        System.out.println("答对了");
                        score += 5;
                    } else {
                        System.out.println();
                        System.out.println("答错了");
                    }
                } else {
                    System.out.println(i + "." + " " + a + "-" + b + "=?");
                    System.out.println("算吧");
                    double sum = scan.nextDouble();
                    if (sum == a - b) {
                        System.out.println("答对了");
                        score += 5;
                    } else {
                        System.out.println("答错了");
                    }
                }
            } else {
                if (a3 > 5) {
                    System.out.println(i + "." + " " + a + "*" + b + "=?");
                    System.out.println("算吧");
                    double sum = scan.nextDouble();
                    if (sum == a * b) {
                        System.out.println("答对了");
                        score += 5;
                    } else {
                        System.out.println();
                        System.out.println("答错了");
                    }
                } else {
                    System.out.println(i + "." + " " + a + "/" + b + "=?");
                    System.out.println("算吧..保留两位小数（四舍五入）");
                    double c =(double)a/b,c2;
                    BigDecimal c1 = new BigDecimal(c);
                    c2 = c1.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
                    double sum = scan.nextDouble();
                    if (sum == c2) {
                        System.out.println("答对了");
                        score += 5;
                    } else {
                        System.out.println("答错了");
                    }
                }
            }
        }System.out.println("总分为：" + score);
    }
}